package com.cheer.controller;

import com.cheer.common.Result;
import com.cheer.service.AuthService;
import com.cheer.service.OaMatrixClassService;
import com.cheer.service.OaMatrixService;
import com.cheer.vo.OaMatrixFrontVO;
import com.cheer.vo.SimpleObjectVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @author cheer
 */
@RestController
@RequestMapping("/matrix")
public class OaMatrixController {

    @Autowired
    private OaMatrixClassService oaMatrixClassService;

    @Autowired
    private OaMatrixService oaMatrixService;

    @Autowired
    private AuthService authService;

    @GetMapping("/list/class")
    public Result<List<SimpleObjectVO>> matrixClass(HttpSession session) {
        authService.getUserId(session);
       return Result.success(oaMatrixClassService.listSimpleByPid(0));
    }

    @GetMapping("/list/item")
    public Result<OaMatrixFrontVO> listByMatrixClass(@RequestParam Integer pid,
                                                     HttpSession session) {
        authService.getUserId(session);
        return Result.success(oaMatrixService.listByMatrixClass(pid));
    }

    @GetMapping("/info/item")
    public Result<String> info(@RequestParam Integer id,
                               HttpSession session) {
        authService.getUserId(session);
        return Result.success(oaMatrixService.getHref(id));
    }

}
